Func _Message_MessageMenu ()
	$sMessages = _Message_LoadMessages ()
	Local $iMessageMenuLoop = True
	While $iMessageMenuLoop
		_Message_DrawMessageMenu ($sMessages)
		_Message_CheckMessageMenuInput ($iMessageMenuLoop)
	WEnd
EndFunc

Func _Message_DrawMessageMenu ($sMessages)
	_GUI_DrawWallpaper ()

	_GUI_DrawButton ("New Message", 20, 10)
	_GUI_DrawButton ("Reload", 130, 10)

	_GDIPlus_GraphicsFillRect($hBuffer, 20, 40, 400, 500, $hButtonBrush)
	_GDIPlus_GraphicsDrawRect($hBuffer, 20, 40, 400, 500)

	$aSplit = StringSplit($sMessages, "|")
	If IsArray("aSplit") Then
		For $i = 0 To $aSplit[0]
			If  $aSplit[$i] <> "" Then
				_GDIPlus_GraphicsDrawRect($hBuffer, 20, $i*14 + 40, 400, 14)
				_GDIPlus_GraphicsDrawString($hBuffer, $aSplit[$i + 1], 20, $i*14 + 40)
			EndIf
		Next
	EndIf

	_Mouse_DrawCursor ()
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
EndFunc

Func _Message_LoadMessages ()
	_BlackCon_SendPacket("msg|get|" & $PLAYER_NAME)
	$hRecvTimer = TimerInit ()
	While 1
		$sRecv = TCPRecv($hServerSocket, 4096)
		If $sRecv <> "" Then
			ExitLoop
		EndIf
		If TimerDiff($hRecvTimer) >= 5000 Then
			MsgBox(0, "", "No reply from server")
			ExitLoop
		EndIf
	WEnd
	Return $sRecv
EndFunc

Func _Message_SendMessage ()
	_BlackCon_SendPacket("msg|accs")
	Local $hTimer = TimerInit ()
	Do
		$sRecv = BinaryToString(TCPRecv($hServerSocket, 4056))
	Until $sRecv <> ""
	$MessageForm = GUICreate("Message", 400, 331, -1, -1, Default, Default, $hGUI)
	$Edit1 = GUICtrlCreateEdit("", 8, 8, 385, 257)
	$Label1 = GUICtrlCreateLabel("Reciever :", 8, 280)
	$Combo1 = GUICtrlCreateCombo("", 62, 280, 145, 25);, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
	GUICtrlSetData(-1, $sRecv, "")
	$ButtonSend = GUICtrlCreateButton("Send", 320, 280, 75, 25)

	GUISetState()

	While 1
		$nMsg = GUIGetMsg()
		Switch $nMsg
			Case $GUI_EVENT_CLOSE
				GUIDelete($MessageForm)
				ExitLoop
			Case $ButtonSend
				_BlackCon_SendPacket("msg|send|" & GUICtrlRead($Edit1) & "|" & GUICtrlRead($Combo1))
				GUIDelete($MessageForm)
				ExitLoop
		EndSwitch
		_GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
	WEnd
EndFunc

Func _Message_CheckMessageMenuInput (ByRef $Loop)
	Select
		Case _IsPressed ('1B')
			$Loop = False
			Sleep(100)
		Case _Mouse_CheckClickedArea (20, 10, 100, 25)
;~ 			_BlackCon_SendPacket("msg|send|" & InputBox("Message", "Text") & "|" & InputBox("Message", "To:" & @crlf & "Paul" & @crlf & "Marian" & @crlf & "Leo" & @crlf & "Blackcent"))
			_Message_SendMessage ()
	EndSelect
EndFunc
